package com.health.listener;

import com.health.common.constant.MQConst;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import java.util.HashMap;

@Component
@RequiredArgsConstructor
@Slf4j
public class EmailListener {
    private final JavaMailSender mailSender;
    @RabbitListener(queues = MQConst.EMAIL_QUEUE)
    public void sendEmail(HashMap<String,String> emailData) {
        log.info("发送邮件：{}", emailData);
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(emailData.get(MQConst.FROM));
        message.setTo(emailData.get(MQConst.TO));
        message.setSubject(emailData.get(MQConst.SUBJECT));
        message.setText(emailData.get(MQConst.CONTEXT));
        //mailSender.send(message);
    }
    @RabbitListener(queues = MQConst.PHONE_QUEUE)
    public void sendPhone(HashMap<String,String> phoneData) {
        log.info("发送短信：{}", phoneData);
    }

}
